package com.mikasa.springboot.example.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.InitBinder;
import redis.clients.jedis.JedisPubSub;

/**
 * Created by User on 17/1/12.
 */

@Service
public class JedisSubscribeTasker implements Runnable {

    @Autowired
    private JedisTemplate jedisTemplate;

    private String channel;//监听的消息通道
    private JedisPubSub jedisPubSub;//消息处理任务

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public void setJedisPubSub(JedisPubSub jedisPubSub) {
        this.jedisPubSub = jedisPubSub;
    }

    @Override
    public void run() {
        // 监听channel通道的消息
        jedisTemplate.subscribe(jedisPubSub, channel);
    }
}
